<!-- 全局配置 -->
<template>
    <div class=''>
        <a-card style="width:100%" :tab-list="tabListNoTitle" :active-tab-key="titleKey"
            @tabChange="key => onTabChange(key)">
            <div v-if="titleKey === 'webInfo'">
                <WebInfo ref="webInfo" @update="get_configWebsite" />
            </div>
            <div v-else-if="titleKey === 'contact'">
                <Contact ref="contact" @update="get_configWebsite" />
            </div>
            <div v-else-if="titleKey === 'iconSet'">
                <IconSet ref="iconSet" @update="get_configWebsite" />
            </div>
        </a-card>
    </div>
</template>

<script>
import WebInfo from './components/webInfo'
import Contact from './components/contact'
import IconSet from './components/iconSet'
import { getConfigWebsite } from '@/api/web/web'
export default {
    components: {
        WebInfo,
        Contact,
        IconSet
    },
    data() {
        return {
            tabListNoTitle: [
                {
                    key: 'webInfo',
                    tab: '网站信息',
                },
                {
                    key: 'contact',
                    tab: '联系方式',
                },
                {
                    key: 'iconSet',
                    tab: '图标设置',
                }
            ],
            titleKey: 'webInfo',
            dataInfo: {}
        }
    },
    computed: {},
    watch: {
        titleKey: {
            handler(val) {
                this.$nextTick(() => {
                    this.setData(val)
                })
            },
            immediate: true
        }
    },
    methods: {
        onTabChange(key) {
            this.titleKey = key;
        },
        async get_configWebsite() {
            let res = await getConfigWebsite()
            this.dataInfo = res.data || {}
            this.setData(this.titleKey)
        },
        setData(refForm) {
            let form = this.$refs[refForm].form
            Object.keys(form).forEach(k => {
                this.$refs[refForm].form[k] = this.dataInfo[k]
            })
            if (refForm === 'contact') {
                this.$refs[refForm].setImage(this.dataInfo.qrcodeUrl)
            }
            if (refForm === 'iconSet') {
                this.$refs[refForm].setImage(this.dataInfo)
            }
        }
    },
    async created() {
        await this.get_configWebsite()
        // this.setData('webInfo')
    },
    mounted() {

    },
}
</script>
<style scoped>
</style>